<?php
/**
 *    首页展示
 *
 *    @author   yanghj 2014.6.21
 *    @usage    none
 */
class DefaultApp extends MallbaseApp
{
    function index()
    {
        header("Location:".WAP_SITE_URL);
        return;
    }
    function make_index()
    {
       $adv_mod =& m('banner');
       $this->import_resource(array(
                'script' => 'index.js',
            )); 
        $this->_config_seo(array(
            'title' => Conf::get('site_title'),
        ));
        $user = $this->visitor->get();
        $wl_recommended_goods = $this->_get_wl_recommended_goods();
        $wl_recommended_goods_one = $wl_recommended_goods[0];
    	$this->assign('index', 1); // 标识当前页面是首页，用于设置导航状态
        $this->assign('icp_number', Conf::get('icp_number'));
        $this->assign('adv_list', $adv_mod->_get_ad(array(1,2,3,4)));//所有的广告图片  
        $this->assign('recommended_goods', $this->_get_recommended_goods(array(11, 12, 13, 14, 15)));//推荐商品
        $this->assign('wl_recommended_goods', ecm_json_encode($wl_recommended_goods));//万菱优选推荐类型下面的商品
        $this->assign('wl_recommended_goods_one', $wl_recommended_goods_one);//万菱优选推荐类型下面第一个类别的商品
        $this->assign('recommended_keyword', $this->_get_recommended_keyword(array(11, 12, 13, 14, 15)));//热门关注
        $this->assign('notices', $this->_get_news_notice());//网站公告        
        $this->assign('page_description', Conf::get('site_description'));
        $this->assign('page_keywords', Conf::get('site_keywords'));
        
        $html = $this->return_display('index.html');
        echo $html;
        file_put_contents("index.html", $html);
    }
    
    /**
     *   推荐类型下面的商品 
     */
    function _get_recommended_goods($recom_ids)
    {
        $arr = array();
        
        if(!is_array($recom_ids))
            $recom_ids = array($recom_ids);
        
        $recommend_mod =& m('recommend');
        $recommend_list = $recommend_mod->find(array(
                'conditions' => 'recom_id ' . db_create_in($recom_ids),
                'fields' => 'recom_id,recom_name',
                'order'     => 'recom_id DESC',
            ));
        if(!$recommend_list)
        {
            return $arr;
        }   
        foreach($recommend_list as $row)
        {
            $arr[$row['recom_id']]['recom_id']   = $row['recom_id'];
            $arr[$row['recom_id']]['recom_name'] = $row['recom_name'];
            $arr[$row['recom_id']]['goods']      = $recommend_mod->get_recommended_goods($row['recom_id'], 8);
        }    
        
        return $arr;
    }

    /**
     *   获取万菱优选推荐类型下面的商品
     */
    function _get_wl_recommended_goods()
    {
        $arr = array();
        $recommend_mod =& m('recommend');
        $recommend_list = array('20'=>'极速上新','21'=>'囤积居奇','22'=>'眼光独特','23'=>'品类繁多','24'=>'各有所好');
        $i = 0;
        foreach($recommend_list as $key=>$row)
        {
            $arr[$i]['recom_id']   = $key;
            $arr[$i]['recom_name'] = $row;
            $arr[$i]['goods']      = $recommend_mod->get_recommended_goods($key, 10);
            if($arr[$i]['goods'])
            {
                foreach($arr[$i]['goods'] as $key=>$val)
                {
                    if( $val['act_id'] > 0)
                    {
                        $act_ids[$val['act_id']] = $val['act_id'];
                    }
                }
            }
            $i++;
        }

        if($act_ids)
        {
            $activity_mod = & m('activity');
            $activity_list = $activity_mod->_get_activity_list($act_ids);//获取参与活动的商品活动数据
            if($activity_list)
            {
                foreach ($arr as $key => $recom)
                {
                    foreach($recom['goods'] as $k=>$v)
                    {
                        if(isset($activity_list[$v['act_id']]))
                        {
                            $arr[$key]['goods'][$k]['act_name'] = $activity_list[$v['act_id']]['act_name'];
                            $arr[$key]['goods'][$k]['free_shipping'] = $activity_list[$v['act_id']]['free_shipping'];
                            $arr[$key]['goods'][$k]['is_promotion'] = 1;
                        }
                    }
                }
            }
        }

        return $arr;
    }
    
    /**
     *   推荐类型下面的热门关注
     */
    function _get_recommended_keyword($recom_ids)
    {
        $keyword_mod =& m('hotkeyword');
        
        return $keyword_mod->get_recommended_keyword($recom_ids, false);
    }
    
    /**
     *   网站公告
     */
    function _get_news_notice()
    {
        $acategory_mod =& m('acategory');
        $article_mod =& m('article');
        $data = $article_mod->find(array(
            'conditions'    => 'cate_id=' . $acategory_mod->get_ACC(ACC_NOTICE) . ' AND if_show = 1',
            'order'         => 'sort_order ASC, add_time DESC',
            'fields'        => 'article_id, title, add_time',
            'limit'         => 2,
        ));   
        return $data;
    }        
}

?>
